<template>
  <div>
    <Top title="设置登录密码" iconShow="1"></Top>
    <div class="setpassword">
      <div class="setpassword-password">
        <input placeholder="请输入6~16位字符密码" v-model="postData.password" />
      </div>
      <div class="setpassword-again">
        <input placeholder="请再次输入密码" v-model="postData.passwordA" />
      </div>
      <mt-button type="primary" class="setpassword-save" @click="savePassword">保存密码</mt-button>
    </div>
  </div>
</template>
<script>
import Top from '../components/Header'
import { MessageBox } from 'mint-ui'
export default {
  name: 'login',
  data() {
    return {
      postData: {
        password: '',
        passwordA: ''
      }
    }
  },
  components: { Top },
  methods: {
    savePassword() {
      let phone = window.sessionStorage.getItem('tel');
      // console.log(phone);
      if (this.postData.password == this.postData.passwordA) {
        if (!(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/.test(this.postData.password))){
          MessageBox.alert('密码需由6~16位数字和密码组成~')
        } else {
          let postData = {
            password: this.postData.password,
            phone: phone
          }
          this.$http.post('/loansupermarket-app/login/updatePwd', postData)
            .then((response) => {
              var resBody = response.body;
              // console.log(resBody)
            })
        }
      } else {
        MessageBox.alert('两次密码输入不一致', '提示');
      }

      // http://127.0.0.1:8081/loansupermarket-app/login/updatePwd?phone=13159663214&oldPassword=123456a&password=123456b
    }
  }
}
</script>
<style lang="scss">
.setpassword {
  margin-top: 1.6rem;
  box-sizing: border-box;
  padding: 0 0.4rem;
  line-height: 1.33rem;
  text-align: left;
  &-password,
  &-again {
    box-sizing: border-box;
    padding: 0 0.6rem;
    margin-top: 0.4rem;
    width: 100%;
    height: 1.33rem;
    background: #fff;
    border-radius: 4px;
    box-shadow: 1px 1px 6px rgba(0, 0, 0, 0.05);
    input {
      outline: none;
      border: none;
      width: 100%;
      height: 1.25rem;
      line-height: 1.33rem;
    }
  }
  .mint-button {
    width: 100%;
    height: 1.33rem;
    font-size: 0.4rem;
    margin-top: 0.93rem;
  }
}
</style>

